package com.yy.wga.resource.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yy.wga.module.goods.entity.bo.GoodsIdBO;
import com.yy.wga.module.resource.entity.pojo.ResourceGoodsCategoryExtendDO;
import com.yy.wga.module.resource.mapper.ResourceGoodsCategoryExtendMapper;
import com.yy.wga.module.resource.service.ResourceGoodsCategoryExtendService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class ResourceGoodsCategoryExtendServiceImpl extends ServiceImpl<ResourceGoodsCategoryExtendMapper, ResourceGoodsCategoryExtendDO> implements ResourceGoodsCategoryExtendService {
    @Resource
    private ResourceGoodsCategoryExtendMapper resourceGoodsCategoryExtendMapper;


    @Override
    public ResourceGoodsCategoryExtendDO getResourceGoodsCategoryExtend(String appKey, Integer categoryId, String shopAppId, String spuId) {
        return this.getOne(new LambdaQueryWrapper<ResourceGoodsCategoryExtendDO>()
                .eq(ResourceGoodsCategoryExtendDO::getAppKey, appKey)
                .eq(ResourceGoodsCategoryExtendDO::getCategoryId, categoryId)
                .eq(ResourceGoodsCategoryExtendDO::getShopAppid, shopAppId)
                .eq(ResourceGoodsCategoryExtendDO::getSpuId, spuId)
                .last("limit 1")
        );
    }

    @Override
    public Integer getMaxSort(String appKey,Integer categoryId) {
        return resourceGoodsCategoryExtendMapper.getMaxSort(appKey,categoryId);
    }

    @Override
    public List<ResourceGoodsCategoryExtendDO> getResourceGoodsCategoryExtendList(String appKey) {
        return this.list(new LambdaQueryWrapper<ResourceGoodsCategoryExtendDO>()
                .eq(ResourceGoodsCategoryExtendDO::getAppKey,appKey));
    }

    @Override
    public void deleteGoods(String appKey, GoodsIdBO goodsIdBO) {
        this.remove(new LambdaQueryWrapper<ResourceGoodsCategoryExtendDO>()
                .eq(ResourceGoodsCategoryExtendDO::getAppKey, appKey)
                .eq(ResourceGoodsCategoryExtendDO::getShopAppid, goodsIdBO.getShopAppid())
                .eq(ResourceGoodsCategoryExtendDO::getSpuId, goodsIdBO.getProductId()));
    }
}
